package com.bw.news.mvvm.viewmodel;

import com.bw.mvvm.entity.BaseEntity;
import com.bw.mvvm.mvvm.viewmodel.BaseViewModel;
import com.bw.news.adapter.NewsValueAdapter;
import com.bw.news.mvvm.model.NewsModel;
import com.bw.mvvm.entity.NewsEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class NewsViewModel extends BaseViewModel<NewsModel> {

    public BaseQuickAdapter baseQuickAdapter = new NewsValueAdapter();

    @Override
    protected void result(BaseEntity entity) {
        if (entity instanceof NewsEntity){
            NewsEntity entity1 = (NewsEntity) entity;
            baseQuickAdapter.setNewInstance(entity1.getData());
        }

    }

    @Override
    public void onCreate() {
        super.onCreate();
        HashMap<String,Object> map = new HashMap<>();
        map.put("id",10);
        m.requestNews(map).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }
}
